from utils.sql_utils import SQLManager
from flask import Blueprint,request

class RecommendService:

    def get_recommend_users():
        current = request.get_json().get("current")
        """
        基于点赞数从高到低推荐用户，并支持分页查询
        :param current: 当前页码
        :param page_size: 每页大小
        :return: 推荐的用户列表
        """
        # SQL 查询，获取用户及其笔记的总点赞数，并按总点赞数降序排列
        sql = """
            SELECT 
                rncl.user_id AS user_id,
                rau.admin_user_name AS user_name,
                rau.avatar_url AS user_avatar_url,
                COUNT(rncl.user_id) AS note_like_counts
            FROM
                rb_note_collections rncl,
                rb_admin_user rau
            WHERE
                rncl.is_deleted = 0
            AND
                rau.unique_id = rncl.user_id
            GROUP BY
                rncl.user_id,
                rau.admin_user_name,
                rau.avatar_url
            ORDER BY
                note_like_counts DESC;
        """
        
        # 执行查询
        result = SQLManager().get_list_by_page(sql, current=int(current))
        
        return result